package com.baobao.demo;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hotel")
public class HotelController {

	static AtomicInteger num = new AtomicInteger(0);

	@RequestMapping(value = "/getHotelInfo", method = RequestMethod.GET)
	public Hotel getHotelInfo(@RequestParam("id") int id, @RequestParam("name") String name) {

		if (num.incrementAndGet() < 6) {
			try {
				System.out.println("执行了超时");
				TimeUnit.MILLISECONDS.sleep(1000);// 用于测试超时
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		return new Hotel(id, name);
	}
}